﻿using System;
using System.Collections.Generic;

namespace PsTFS.Objects
{
    /// <summary>
    /// Classe permettant de loguer les évenements
    /// </summary>
    public class Log
    {
        /// <summary>
        /// Permet de savoir si on enregistre les logs oou pas
        /// </summary>
        public static bool bLog { get; set; }
        /// <summary>
        /// Date du log
        /// </summary>
        public DateTime Date { get; set; }
        /// <summary>
        /// Personne à l'origine du log
        /// </summary>
        public String Owner { get; set; }
        /// <summary>
        /// Message à loguer
        /// </summary>
        public String msg { get; set; }
        /// <summary>
        /// Event à l'origine du log
        /// </summary>
        public EventArgs e { get; set; }

        /// <summary>
        /// Liste contenant tous les logs
        /// </summary>
        private static List<Log> Logs = new List<Log>();

        /// <summary>
        /// Permet d'ajouter un log dans PsTFS
        /// </summary>
        /// <param name="e">Event qui à déclancher le log</param>
        /// <param name="msg">Message d'erreur</param>
        public static void AddLog(EventArgs e, string msg)
        {
            if (bLog)
            {
                Log l = new Log();
                l.Date = DateTime.Now;
                l.e = e;
                l.msg = msg;
                l.Owner = Context.GetContext().User;
                Logs.Add(l);
            }
        }

        /// <summary>
        /// Permet de nétoyer les log de PsTFS
        /// </summary>
        /// <returns></returns>
        public static bool ClearLog()
        {
            Logs = new List<Log>();
            if (Logs.Count > 0)
                return false;
            else
                return true;
        }

        /// <summary>
        /// Permet de visioner les logs
        /// </summary>
        /// <returns>Liste contenant des objets PsLog</returns>
        public static List<Log> GetLog()
        {
            return Logs;
        }

        /// <summary>
        /// Ajout d'un log hors evennement
        /// </summary>
        /// <param name="msg">Message à loguer</param>
        public static void AddLog(string msg)
        {
            if (bLog)
            {
                Log l = new Log();
                l.Date = DateTime.Now;
                l.e = null;
                l.msg = msg;
                l.Owner = Context.GetContext().User;
                Logs.Add(l);
            }
        }
    }
}
